home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ClockObj.cpp
-
- Contains: Object accessor implementation for the AppleTest_ClockPart
-
- Owned by: Jon Pugh
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <8> 11/2/95 RR Renamed module AppleTestClock->AppleTest
- <7> 25/09/95 NP 1979071: Check results of operator new.
- <6> 9/11/95 NP 1272294: Messaging code cleanup.
- <5> 9/4/95 TJ Added Includes to Compile with out
- PC-Headers.
- <4> 7/12/95 TJ Moved declerations out of switch statement
- so that it would compile with SCpp.
- <3> 7/10/95 JP Scripting cleanup
- <2> 6/30/95 JP Accessor foo
- <1> 6/13/95 JP first checked in
- To Do:
- */
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" /* Use C++ savvy ODPoint and ODRect */
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODOSLToken_xh
- #include <ODOSLTkn.xh>
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _CLOCKOBJ_
- #include "ClockObj.h"
- #endif
-
- #ifndef _CLOCKDEF_
- #include "ClockDef.h"
- #endif
-
- #ifndef _CLKPRPAC_
- #include "ClkPrpAc.h"
- #endif
-
- #ifndef _CLOCKPRT_
- #include "ClockPrt.h"
- #endif
-
- //#ifndef _DFRMITER_
- //#include "DFrmIter.h"
- //#endif
-
- #ifndef SOM_ODDraft_xh
- #include "Draft.xh"
- #endif
-
- #ifndef SOM_Module_AppleTest_defined
- #include "Clock.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include "Facet.xh"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include "Frame.xh"
- #endif
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include "NamRslvr.xh"
- #endif
-
- #ifndef SOM_ODPart_xh
- #include "Part.xh"
- #endif
-
- #ifndef SOM_CLOCKSI_xh
- #include "ClockSI.xh"
- #endif
-
- #ifndef _SIHELPER_
- #include "SIHelper.h"
- #endif
-
- #ifndef _ODREGISTRY_
- #include "ODRgstry.xh"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include "ODSessn.xh"
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef SOM_ODShape_xh
- #include "Shape.xh"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include "StorageU.xh"
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include "Trnsform.xh"
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include "MssgIntf.xh"
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include "FrFaItr.xh"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef __AEPACKOBJECT__
- #include <AEPackObject.h>
- #endif
-
- #ifndef __AEREGISTRY__
- #include <AERegistry.h>
- #endif
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef __TEXTUTILS__
- #include <TextUtils.h>
- #endif
-
- #include <string.h>
-
- #pragma segment ClockObj
-
-
-
- //==============================================================================
- // Function prototypes
- //==============================================================================
-
- static void CreatePartObjectSpec(DescType keyForm, AEDesc* containerObjSpec,
- AEDesc *objectSpec);
- void GetDirectParam(ODSession* session, AppleEvent* message,
- AEDesc* evtDp);
-
- void InstallStaticCallbacks(SIHelper* helper, ClockPart* clock)
- {
- ODObjectAccessorUPP theAccessorUPP ;
-
- theAccessorUPP = NewODObjectAccessorProc( GetPropertyFromNULL ) ;
- helper->InstallObjectAccessor(cProperty, typeNull, theAccessorUPP,
- (ODSLong)clock);
-
- ODEventHandlerUPP theEventHandlerUPP ;
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleSetData ) ;
- helper->InstallEventHandler(kAECoreSuite, kAESetData,
- theEventHandlerUPP,
- (ODSLong)clock);
-
- theEventHandlerUPP = NewODEventHandlerProc( HandleGetData ) ;
- helper->InstallEventHandler(kAECoreSuite, kAEGetData,
- theEventHandlerUPP,
- (ODSLong)clock);
-
- ODDisposeTokenUPP disposeTokenUPP
- = NewODDisposeTokenProc( ClockDisposeToken ) ;
- helper->InstallDisposeTokenProc( disposeTokenUPP, (ODSLong)clock);
- }
-
-
- //------------------------------------------------------------------------------
- // GetPropertyFromNULL
- //------------------------------------------------------------------------------
-
- static pascal ODError GetPropertyFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon)
- {
- ODUnused(desiredClass);
- ODUnused(container);
- ODUnused(containerClass);
-
- Environment* ev = somGetGlobalEnvironment();
- ClockPart* clock = (ClockPart*)refCon;
- ODSession* session = clock->GetSession();
- ODNameResolver* resolver = session->GetNameResolver(ev);
- DescType propID;
- ClockPropAccessor* accessorObj;
- ODError error = noErr;
- AEDesc realData = NULL_DESCRIPTOR_DEFINITION;
- AEDesc tokenDesc = NULL_DESCRIPTOR_DEFINITION;
-
- TRY
-
- if (form != formPropertyID)
- THROW(errAEEventNotHandled);
-
- THROW_IF_ERROR( ODDescToAEDesc( selectionData, &realData ) );
-
- switch(propID = **(DescType**)(realData.dataHandle))
- {
- case pFont:
- case pPointSize:
- case pTextStyles:
- case pDisplayMode:
- case pASTime:
- if ( !resolver->IsODToken( ev, value ) )
- THROW( errAEEventNotHandled /*errAENoSuchObject*/ );
- tokenDesc.descriptorType = cProperty;
- tokenDesc.dataHandle = NewHandle(sizeof(accessorObj));
- THROW_IF_ERROR(MemError());
-
- accessorObj = new ClockPropAccessor(propID, clock);
- SETFIRSTBYTESOFHANDLE(tokenDesc.dataHandle, ClockPropAccessor*,
- accessorObj);
-
- ODDesc* userODDesc = resolver->GetUserToken(ev, value);
- THROW_IF_ERROR( AEDescToODDesc( &tokenDesc, userODDesc ) );
- break;
- default:
- THROW(errAEEventNotHandled);
- break;
- }
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- AEDisposeDesc( &tokenDesc );
- AEDisposeDesc( &realData );
- return error;
- } // GetPropertyFromNULL()
-
-
-
- //------------------------------------------------------------------------------
- // HandleSetData
- //------------------------------------------------------------------------------
-
- static pascal ODError HandleSetData(ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- AEDesc theData = NULL_DESCRIPTOR_DEFINITION;
- AEDesc evtDp = NULL_DESCRIPTOR_DEFINITION;
- AEDesc theToken = NULL_DESCRIPTOR_DEFINITION;
- AppleEvent realMessage = NULL_DESCRIPTOR_DEFINITION;
- AppleEvent realReply = NULL_DESCRIPTOR_DEFINITION;
- ODError error = noErr;
-
- Environment* ev = somGetGlobalEnvironment();
- ClockPart* clock = (ClockPart*)handlerRefcon;
- ODSession* session = clock->GetSession();
- ODNameResolver* resolver = session->GetNameResolver(ev);
-
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage) );
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply ));
-
- ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- THROW_IF_ERROR(AEGetKeyDesc(&realMessage, keyAEData,
- typeWildCard, &theData));
-
- GetDirectParam( session, &realMessage, &evtDp);
- tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
- if ( !resolver->IsODToken( ev, tmpWrapper ) )
- THROW( errAENoSuchObject );
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- error = ODDescToAEDesc(myTokenODDesc, &theToken );
-
- if (error == noErr)
- {
- switch (theToken.descriptorType)
- {
- case typeProperty:
- ClockPropAccessor* embedPropAccessorObj =
- FIRSTBYTESFROMHANDLE(theToken.dataHandle, ClockPropAccessor*);
- embedPropAccessorObj->SetData(&theData);
- delete embedPropAccessorObj;
- break;
-
- default:
- ASSERTM(false, errAECantSupplyType, "You shouldn't be here");
-
- }
- }
- THROW_IF_ERROR(error);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- AEDisposeDesc( &theToken );
- AEDisposeDesc( &theData );
- AEDisposeDesc( &evtDp );
- AEDisposeDesc( &realMessage );
- AEDisposeDesc( &realReply );
- ODDeleteObject( tmpWrapper );
- return error;
- } // HandleSetData()
-
-
- //------------------------------------------------------------------------------
- // HandleGetData
- //------------------------------------------------------------------------------
-
- static pascal ODError HandleGetData(ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(part);
- ODUnused(handlerRefcon);
-
- DescType reqType;
- Size theSize;
- ODError error;
- Environment* ev = somGetGlobalEnvironment();
- ClockPart* clock = (ClockPart*)handlerRefcon;
- ODSession* session = clock->GetSession();
- ODNameResolver* resolver = session->GetNameResolver(ev);
-
- AEDesc objectData = NULL_DESCRIPTOR_DEFINITION;
- AEDesc evtDp = NULL_DESCRIPTOR_DEFINITION;
- AEDesc token = NULL_DESCRIPTOR_DEFINITION;
- AppleEvent realMessage = NULL_DESCRIPTOR_DEFINITION;
- AppleEvent realReply = NULL_DESCRIPTOR_DEFINITION;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- GetDirectParam( session, &realMessage, &evtDp);
- tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
- if ( !resolver->IsODToken( ev, tmpWrapper ) )
- THROW( errAENoSuchObject );
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &token ) );
-
- // Next, get the requested return type, if it exists.
- error = AEGetParamPtr(&realMessage, keyAERequestedType, typeType,
- &reqType, (Ptr)&reqType, sizeof(reqType), &theSize);
- if (error == errAEDescNotFound) // Not an error if return type is not found.
- {
- error = noErr;
- reqType = typeWildCard;
- }
- THROW_IF_ERROR(error);
-
- switch (token.descriptorType)
- {
- case typeProperty:
- ClockPropAccessor* propAccessorObj = FIRSTBYTESFROMHANDLE(
- token.dataHandle, ClockPropAccessor*);
- propAccessorObj->GetData(&objectData);
- delete propAccessorObj;
- break;
- default:
- ASSERTM(false, errAECantSupplyType, "You shouldn't be here");
-
- }
-
- error = AEPutParamDesc( &realReply, keyAEResult, &objectData );
- THROW_IF_ERROR(error);
- THROW_IF_ERROR( AEDescToODDesc( &realReply, reply ) );
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- AEDisposeDesc( &token );
- AEDisposeDesc( &evtDp );
- AEDisposeDesc( &objectData );
- AEDisposeDesc( &realMessage );
- AEDisposeDesc( &realReply );
- ODDeleteObject( tmpWrapper );
- return error;
- } // HandleGetData()
-
-
- //------------------------------------------------------------------------------
- // ClockCompare
- // For now, just handle what we need to handle
- //------------------------------------------------------------------------------
- static pascal ODError ClockCompare( ODPart* thePart,
- DescType oper,
- ODOSLToken* obj1,
- ODOSLToken* obj2,
- ODBoolean* result,
- ODSLong refCon)
- {
- ODUnused(thePart);
- ODUnused(obj1);
- ODUnused(result);
- ODUnused(refCon);
-
- ODError error = noErr;
- Environment* ev = somGetGlobalEnvironment();
- ClockPart* clock = (ClockPart*)refCon;
- ODNameResolver* resolver = clock->GetSession()->GetNameResolver(ev);
- ODBoolean isChar = kODFalse;
- ODDesc* tokenWrapper = kODNULL;
- AEDesc realToken;
-
- switch(oper)
- {
- case kAEEquals:
- tokenWrapper = resolver->GetUserToken(ev, obj2);
- error = ODDescToAEDesc( tokenWrapper, &realToken );
- isChar = realToken.descriptorType == typeChar;
- AEDisposeDesc( &realToken );
- if (isChar)
- break;
- default:
- error = errAEEventNotHandled;
- }
-
- return error;
- }
-
- //------------------------------------------------------------------------------
- // ClockCount
- //------------------------------------------------------------------------------
- static pascal ODError ClockCount( ODPart* thePart,
- DescType desiredType,
- DescType containerClass,
- ODOSLToken* container,
- ODSLong* result,
- ODSLong refCon)
- {
- ODUnused(thePart);
- ODUnused(desiredType);
- ODUnused(containerClass);
- ODUnused(container);
- ODUnused(result);
- ODUnused(refCon);
- return errAEEventNotHandled;
- }
-
- //------------------------------------------------------------------------------
- // ClockDisposeToken
- //------------------------------------------------------------------------------
- static pascal ODError ClockDisposeToken(ODPart* thePart,
- ODOSLToken* unneededToken,
- ODSLong refCon)
- {
- ODUnused(thePart);
- ODUnused(unneededToken);
- ODUnused(refCon);
- return errAEEventNotHandled;
- }
-
- //------------------------------------------------------------------------------
- // Utility functions
- //------------------------------------------------------------------------------
-
- void GetDirectParam(ODSession* session, AppleEvent* message,
- AEDesc* evtDp)
- {
- Environment* ev = somGetGlobalEnvironment();
- AEDesc localDP;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &localDP));
-
- ODNameResolver* resolver = session->GetNameResolver(ev);
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
-
- ODBoolean isToken = resolver->IsODToken(ev, tmpWrapper);
- ODDeleteObject( tmpWrapper );
- if ( isToken )
- {
- *evtDp = localDP;
- }
- else
- {
- AEDisposeDesc(&localDP);
- WARN("RlShlEv.cpp: GetDirectParam. Found a non-token. About to throw.");
- THROW( errAEEventNotHandled );
- }
- } // GetDirectParam()
-
-
- //------------------------------------------------------------------------------
- // CreatePartObjectSpec
- //------------------------------------------------------------------------------
-
- static void CreatePartObjectSpec(DescType keyForm, AEDesc* containerObjSpec,
- AEDesc *objectSpec)
- {
- // We'll really return a spec to the FRAME containing the part.
- // This cause you can get to the part from the frame, but not the other
- // way 'round.
-
- AEDesc keyData;
-
- switch(keyForm)
- {
- case formAbsolutePosition :
- long index = 1; // <eeh> we should figure out where
- THROW_IF_ERROR(AECreateDesc(typeLongInteger, &index, sizeof(index),
- &keyData));
- break;
- default :
- ASSERTM(false, -1, "Can't handle that form!!! (yet)");
- }
-
- CreateObjSpecifier(cPart, containerObjSpec, keyForm, &keyData, true,
- objectSpec);
- } // CreatePartObjectSpec()
-
-
-